package top.lyc829.zzl_android.ui.profile.follow.team;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import java.io.IOException;
import java.util.List;

import okhttp3.Response;
import top.lyc829.zzl_android.logic.bean.ResultBean;
import top.lyc829.zzl_android.logic.bean.TeamSimpleBean;
import top.lyc829.zzl_android.logic.network.Network;
import top.lyc829.zzl_android.logic.util.HttpUtil;
import top.lyc829.zzl_android.logic.util.Utils;
import top.lyc829.zzl_android.logic.util.gson.JsonUtilNew;

public class FollowTeamViewModel extends ViewModel {
    // TODO: Implement the ViewModel
    private MutableLiveData<List<TeamSimpleBean>> followTeamLiveData;

    public MutableLiveData<List<TeamSimpleBean>> getFollowTeamLiveData() {

        if (followTeamLiveData==null)
        {
            followTeamLiveData=new MutableLiveData<>();
        }
            return followTeamLiveData;
    }


    public void getFollowTeanList(int userId)
    {
        Network.getFollowTeamList(userId,new HttpUtil.MyCallback() {
            @Override
            public void success(Response res) throws IOException {
                String resultStr=res.body().string();
                ResultBean<List<TeamSimpleBean>> resultBean= JsonUtilNew.fromJsonArray(resultStr,TeamSimpleBean.class);

                if(resultBean.getCode().equals(200))
                {
                    getFollowTeamLiveData().postValue(resultBean.getData());
                }
                else
                    failed(new IOException(resultBean.getMsg()));
            }

            @Override
            public void failed(IOException e) {
                getFollowTeamLiveData().postValue(null);
                Utils.Sout(e.getMessage());
            }
        });
    }

}